package com.qcby.byc.demo0422.controller;

import com.qcby.byc.demo0422.entity.Depart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.beans.PropertyEditorSupport;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @className: Demo0425Controller
 * @description:
 * @author: lxt
 * @create: 2021-04-25 14:29
 **/
@Controller
@RequestMapping("demo0425")
public class Demo0425Controller {


    protected Logger logger = LoggerFactory.getLogger(getClass());

    @RequestMapping("add")
    @ResponseBody
    public Depart addDemo(Depart depart){
        System.out.println("depart:"+depart);
        return depart;
    }


    /**
     *  F9   跨断点执行，遇到断点停止，没有断点直到运行结束
     *  F8  单步执行
     *  F7  进入方法内容
     *  alt+f8  执行表达式
     *  ctrl+shift+f8
     *      1.断点所在行  =>  条件断点；（循环里面）
     *      2.非断点所在行  => 快速去掉指定或者所有断点
     *
     *      用途：调试解决问题  &   源码调试（必备）
     * @param args
     */


    /**
     *
     *
     *
     * @param args
     */

    public static void main(String[] args) {

        // 旧的（jdk7以及低于jdk7版本的）时间api里面的日期类型
        Date now = new Date();
        Date date1 = new Date(2021-1900,11,9);


        String name = "qcby1";
//        Date now1 =  new Date(2021,05,04);

        //  Mon Aug 23 21:56:25 CST 2021
        //  Wed Nov 10 21:28:01 CST 2021
        System.out.println(now);
        System.out.println("date1:"+date1);

        // jdk1.8时候  新的时间api
        System.out.println(LocalDate.now());
        // 创建时间 修改时间
        System.out.println(LocalDateTime.now());
        //  第几节课开始或者结束时间
        System.out.println(LocalTime.now());

        /**
         *
         *   2021/11/10 21:32:21
         *   2021-11-10 21:32:21
         *   20211110 21:32:21
         */
        //  时间格式化
        // 要求输出  2020-20-02 10:10:10
        /**
         *
         */
        System.out.println("****************0823**********************");
        Date dateNow = new Date();
        System.out.println(dateNow);

        String pattern = "yyyy-MM-dd";
        //  DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
        // parse => 字符串 格式化成时间    format=> 时间格式化成功字符串
        DateFormat dateFormat1 = new SimpleDateFormat(pattern);
//        Date date = new Date(2021,5,27);
//        hello();
        // 时间日期类型
        Date date = null;
        try {
            String dateStr = "2021-11-09";
            //  将Sting类型的 时间字符串  解析转化成  Date类型
            date = dateFormat1.parse(dateStr);
            System.out.println("2021-11-09:"+date);
        } catch (ParseException e) {
            e.printStackTrace();
        }


        System.out.println("===================1110=======================");



//        String strDateFormat1 = "yyyy-MM-dd HH:mm:ss";
        /**
         *
         */
        // HH =>  二十四小时。
        String strDateFormat1 = "yyyy/MM/dd HH:mm:ss";
        // hh =>  十二小時
//        String strDateFormat1 = "yyyy/MM/dd hh:mm:ss";
        SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat1);
        // 按照指定模板 格式化Date类型为String类型
        Date date2 = new Date();
        System.out.println("date-format："+sdf.format(date2));

        System.out.println("===================以上  jdk7时间日期api的简单使用=======================");
        LocalDate localDate = LocalDate.of(2021,11,11);

        LocalDateTime localDateTime21 = LocalDateTime.of(2021,11,11,0,0,0);

        LocalTime localTime21 =  LocalTime.of(23,59,59);

        System.out.println("【新localDate】:"+localDate);
        System.out.println("【localDateTime21】:"+localDateTime21);
        System.out.println("【localTime21】:"+localTime21);
        // 格式化
        String localDateFormat = "yyyy/MM/dd";

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(localDateFormat);
        String localDateStr = localDate.format(dateTimeFormatter);
        System.out.println("【新-2021-format】:"+localDateStr);

        String dateStr = "2021/11/11";
        LocalDate localDate1 = LocalDate.parse(dateStr,dateTimeFormatter);

        System.out.println("【新-字符串转时间】:"+localDate1);
        System.out.println("【新-字符串转时间-当前年】:"+localDate1.getDayOfYear());

        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println("localDateTime:"+localDateTime);
        String strDateFormat = "yyyy-MM-dd HH:mm:ss";
        System.out.println("localDateTime-format:"+localDateTime.format(DateTimeFormatter.ofPattern(strDateFormat)));
        System.out.println("****************0528**********************");
        System.out.println("===============================");
        System.out.println(localDateTime.getYear());
        System.out.println(localDateTime.getMonth());
        System.out.println(localDateTime.getDayOfWeek());
        System.out.println(localDateTime.plusDays(5));
        System.out.println(localDateTime.plusDays(-5));
        System.out.println(localDateTime.plusMonths(3));
        System.out.println(localDateTime.plusYears(2));
        System.out.println("===============================");
        // 比较时间  时间1.isBefore(时间2) ？ =>  true  或者 false
        System.out.println(localDateTime.plusYears(-2).isBefore(localDateTime));
        System.out.println(localDateTime.plusYears(2).isBefore(localDateTime));

    }

    public static void hello(){
        System.out.println("hello world!");
    }

}
